package chapter4.No4_1_使用reentrantLock类.demo8;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * !
 *
 * @author liujian
 * @version 2016/11/21 0021
 */
public class C {

    ReentrantLock lock;
    Condition conditionP;
    Condition conditionC;

    public C(ReentrantLock lock, Condition conditionP, Condition conditionC) {
        this.lock = lock;
        this.conditionP = conditionP;
        this.conditionC = conditionC;
    }

    public void xf() throws InterruptedException {
        lock.lock();
        while(Tools.count == 0) {
            System.out.println("没有能消费的，消费线程进入waiting状态!");
            conditionC.await();
        }
        Thread.sleep(500);
        Tools.count = 0;
        System.out.println("消费了一个☆,count="+Tools.count);
        conditionP.signal();
        lock.unlock();
    }

}
